// pages/register/register.js
Page({
    data: {},
    //表单提交按钮
    submit: function (e) {
        console.log('form发生了submit事件，携带数据为：', e.detail.value)
        if (e.detail.value.username != '' && e.detail.value.password != '' && e.detail.value.nickName != '') {
            var _this = this;
            wx.showLoading({
                title: '加载中',
                mask: true
            })
            wx.request({
                url: 'http://43.139.97.111:8080/user/insert',
                data: {
                    avatar: '/files/13_20221226200502874.png',
                    "nickName": e.detail.value.nickName,
                    "password": e.detail.value.password,
                    "userName": e.detail.value.username
                },
                header: {
                    'content-type': 'application/json' // 默认值
                },
                method: 'POST',
                success: function (res) {
                    console.log("res", res);
                    if (res.data.code == 200) {
                        wx.navigateTo({
                            url: '/pages/login/login',
                        })
                    }else{
                        wx.showModal({
                            title: '提示',
                            content: res.data.data,
                            success(res) {
                              if (res.confirm) {
                                console.log('用户点击确定')
                              } else if (res.cancel) {
                                console.log('用户点击取消')
                              }
                            }
                          })
                    }
                    wx.hideLoading()

                },
                fail: function (res) {},
                complete: function (res) {},
            })

        }else{
            wx.showModal({
                title: '提示',
                content: '请输入完整信息',
                success(res) {
                  if (res.confirm) {
                    console.log('用户点击确定')
                  } else if (res.cancel) {
                    console.log('用户点击取消')
                  }
                }
              })
        }
    },
    back: function (e) {
        wx.navigateTo({
            url: '/pages/login/login',
        })
        this.setData({

        })

    }
})